Contents

import pandas as pd
import plotly.express as px

from plotly.offline import init_notebook_mode
init_notebook_mode()

df = pd.read_csv('../data/capture_fisheries.csv', skiprows=4)
df = df.dropna(how='all')

years = [str(year) for year in range(1960, 2025)]
df_melted = df.melt(
    id_vars=["Country Name", "Country Code", "Indicator Name", "Indicator Code"],
    value_vars=years,
    var_name="Year",
    value_name="Capture Production (metric tons)"
)

df_melted['Year'] = pd.to_numeric(df_melted['Year'])
df_melted['Capture Production (metric tons)'] = pd.to_numeric(
    df_melted['Capture Production (metric tons)'], errors='coerce'
)
df_melted = df_melted.dropna(subset=['Capture Production (metric tons)'])

world_totals = df_melted.groupby('Year')['Capture Production (metric tons)'].sum().reset_index()

fig = px.line(
    world_totals,
    x='Year',
    y='Capture Production (metric tons)',
    labels={'Capture Production (metric tons)': 'Total Capture (metric tons)'},
    color_discrete_sequence=['#87cefa'],
    markers=True
)

fig.update_layout(
    xaxis_title='Year',
    yaxis_title='Total Capture Production (metric tons)',
    hovermode='x unified',
    showlegend=False,
    template='plotly_white',
    font=dict(color='#0a2463'),
    margin={'l': 30, 'b': 130, 'r': 30, 't': 30},
    title={
        'text': '<b>Global Capture Fisheries Production (1960-2024)</b>',
        'x': 0.5,
        'xanchor': 'center',  
    }
)

fig.update_traces(
    hovertemplate='<b>Year:</b> %{x}<br><b>Total Capture:</b> %{y:,} metric tons'
)

fig.add_annotation(x=-0.02, y=-0.27,
                   xref="paper", yref="paper",
                   showarrow=False,
                   align='left',
                   xanchor='left', yanchor='bottom',
                   text="World total capture fisheries production for the years 1960-2024. <br>" + \
                        'Capture fisheries refer to the harvesting of wild fish and seafood from natural water bodies such as oceans, rivers,<br> '
                        'and lakes. Hover to see specific data for different years.')

fig.update_annotations(
    font=dict(color='#0a2463')
)

fig.show()